#ifndef SCL_READER_H
#define SCL_READER_H
#include <QtCore>
#include <QList>

class scl_reader : public QXmlStreamReader
{
     //Q_OBJECT
public:

    scl_reader();
    bool read(QIODevice *device);

    struct Add{
        QString MAC;
        QString VID;
        QString VPRIORITY;
        QString APPID;
        QString smpRate;
        QString asdu;
    };
    struct Fc{
        QString lnClass;
        QString daName;
        QString doName;
        QString desc;
        QString doi;
        QString dai;
    };
    struct Sub{
        QString SID;    //goID;appID
        QString type;
        QString iedName;
        QString name;//SMV ;GSE
        int num;
        struct Add add;
        QList<Fc> fc;
    };
    QList<Sub> PSUB;

private:
    struct Fc tempfc;
    struct Sub tempSub;
    struct Address{
        QString MAC;
        QString VID;
        QString VPRIORITY;
        QString APPID;
        QString sID;
        QString num;
    };
    struct GseorSmv{
        QString name;
        QString cbname;
        QString ldInst;
        struct Address address;
    };
    struct ConnAP{
        QString apName;
        QString iedName;
      //  struct GseorSmv gv[10];
        QList<GseorSmv> gv;
    };
    struct Pcom{
        QString type;
     //   struct ConnAP connap[100];
        QList<ConnAP> connap;
    };
  //  struct Pcom PCOM[10];
    struct GseorSmv tempgv;
    struct ConnAP tempConnAP;
    struct Pcom tempPCOM;
    QList<Pcom> PCOM;
    int pcNum;
    int apNum;
    int gvNum;

    struct Fcda{
        QString lnClass;
        QString lnInst;
        QString desc;
        QString doName;
        QString daName;
        QString dOI;
        QString dAI;
        QString prefix;
    };
    struct Dataset{
        QString name;
        int num;
      // struct Fcda fcda[100];
        QList<Fcda> fcda;
    };
    struct Control{
        QString DatSet;
        QString name;
        QString appID;
        QString smpRate;
        QString asdu;
    };
    struct Doi{
        QString name;
        QString desc;
        QString DAI;
    };
    struct DDOI{
        QString name;
        QString desc;
        QString dai;
    };

    struct Ln{
        QString lnClass;
        QString lnSt;
        QString desc;
        QString prefix;
     //   struct Doi doi[150];
        QList<Doi> doi;
    };
    struct Ldevice{
        QString inst;
     //   struct Dataset dataset[30];
     //   struct Control control[10];
        QList<DDOI> doi;
        QList<Dataset> dataset;
        QList<Control> control;
     //   struct Ln ln[150];
        QList<Ln> ln;
    };

    struct AccessPoint{
        QString name;
     //   struct Ldevice ld[5];
        QList<Ldevice> ld;
    };

    struct Pied{
        int num;
        QString name;
    //    struct AccessPoint accp[10];
        QList<AccessPoint> accp;
    };
    struct Fcda tempfcda;
    struct Doi tempdoi;
    struct Ln templn;
    struct Control tempcontrol;
    struct Dataset tempdataset;
    struct DDOI tempddoi;
    struct Ldevice templd;
    struct AccessPoint tempaccp;
    struct Pied tempPIED;
    QList<Pied> PIED;
    int piNum;
    int acNum;
    int daNum;
    int coNum;
    int fcNum;
    int lnNum;
    int doNum;
    int ldNum;
    int ddoNum;
private:
 //   int SMVorGOOSE;   //0:smv; 1:goose;
    void read_data();
    void read_Communication();
    void read_SubNetwork();
    void read_IED();
  //  void read_SubNetwork();
    void read_ConnectedAP();
    void read_GSE();
    void read_SMV();
    void read_Address();
    void read_P();

    void read_LDevice();
    void read_DataSet();
    void read_DDOI();
    void read_AccessPoint();
    void read_LN();
    void read_LN0();
    void read_control();
    void read_FCDA();

    void read_GSEControl();
    void read_SampledValueControl();
   // void read_LN();
    void read_LNdata();
    void read_DOI();
    void read_DAI();
    void read_Val();

    void connectData();
    void clearTemp();
};
#endif // SCL_READER_H
